import { ComponentType } from './index';
import type { CSSProperties } from 'vue';
import type { ButtonProps } from '@arco-design/web-vue/lib/button';
import type { RowProps, ColProps } from '@arco-design/web-vue/es/grid/interface';
import type { FieldRule } from '@arco-design/web-vue/es/form/interface';

export interface componentProps {
  options?: any[];
  placeholder?: string;
  showButton?: boolean;
  onInput?: () => Recordable;
  onChange?: () => Recordable;
}

export interface FormSchema {
  field: string;
  label: string;
  showColon?: boolean;
  noStyle?: boolean;
  disabled?: boolean;
  help?: string;
  extra?: string;
  required?: boolean;
  rules?: object | object[];
  validateStatus?: string;
  validateTrigger?: string;
  labelColProps?: Partial<ColProps>;
  wrapperColProps?: Partial<ColProps>;
  hideLabel?: boolean;
  hideAsterisk?: boolean;
  labelColStyle?: object;
  wrapperColStyle?: object;
  rowProps?: Partial<RowProps>;
  rowClass?: string | [] | object;
  contentClass?: string | [] | object;
  //自定义
  labelMessage?: string;
  labelMessageStyle?: object | string;
  defaultValue?: any;
  component?: ComponentType;
  componentProps?: any;
  slot?: string;
  isFull?: boolean;
  suffix?: string;
  showFeedback?: boolean;
  showLabel?: boolean;
  requireMarkPlacement?: string;
  hidden?: boolean;
  colProps?: Partial<ColProps>;
}

export interface FormProps {
  model?: Recordable;
  layout?: string;
  size?: string;
  labelColProps?: Partial<ColProps>;
  wrapperColProps?: Partial<ColProps>;
  labelAlign?: string;
  disabled?: boolean;
  rules?: FieldRule[];
  //自定义
  schemas?: FormSchema[];
  labelWidth?: number;
  inline?: boolean;
  labelPlacement?: string;
  isFull?: boolean;
  actInheritLabelCol?: boolean;
  showActionButtonGroup?: boolean;
  showResetButton?: boolean;
  resetButtonOptions?: Partial<ButtonProps>;
  showSubmitButton?: boolean;
  showAdvancedButton?: boolean;
  submitButtonOptions?: Partial<ButtonProps>;
  submitButtonText?: string;
  resetButtonText?: string;
  rowProps?: object;
  colProps?: Partial<ColProps>;
  resetFunc?: () => Promise<void>;
  submitFunc?: () => Promise<void>;
  submitOnReset?: boolean;
  baseRowStyle?: CSSProperties;
  actionStyle?: CSSProperties;
  draggable?: boolean;
}

export interface FormActionType {
  submit: () => Promise<any>;
  setProps: (formProps: Partial<FormProps>) => Promise<void>;
  setSchema: (schemaProps: Partial<FormSchema[]>) => Promise<void>;
  setFieldsValue: (values: Recordable) => void;
  clearValidate: (name?: string | string[]) => Promise<void>;
  getFieldsValue: () => Recordable;
  resetFields: () => Promise<void>;
  validate: (nameList?: any[]) => Promise<any>;
  mergeValidateInfo?: (items: any[]) => object;
  setLoadingSub: (status: boolean) => void;
  validateInfos?: object;
}

export type RegisterFn = (formInstance: FormActionType) => void;

export type UseFormReturnType = [RegisterFn, FormActionType];
